package com.dhu.graph.basic.GraphImpls;

import com.dhu.graph.basic.AbstractGraph;
import com.dhu.graph.basic.edge.DirectedEdge;
import com.dhu.graph.basic.edge.Edge;
import com.dhu.graph.utils.Bag;
import com.sun.corba.se.impl.orbutil.graph.Graph;

import java.io.Serializable;

/**
 * @ Author ：snow
 * @ Date   ：Created in 2020-05-13
 * @ Description：
 * @ Modified By：
 * @ Version:
 */
public class EdgeWeightedDiGraph implements Serializable, AbstractGraph {
    private static final long SERIALIZABLE_UID = 2376566763426234L;


    private int V;
    private int E;
    private Bag<DirectedEdge>[] adj;

    public EdgeWeightedDiGraph(int v){
        this.V = v;
        this.adj = (Bag<DirectedEdge>[]) new Bag[v];
        for (int i = 0; i < v; ++i){
            adj[i] = new Bag<DirectedEdge>();
        }
    }


    @Override
    public int E() {
        return this.E;
    }

    @Override
    public int V() {
        return this.V;
    }

    @Override
    public Iterable<DirectedEdge> adj(int v) {
        return adj[v];
    }

    @Override
    public void addEdge(int v, int w) {
        throw new RuntimeException("Not support in this calss ,expected DirectedEdge");
    }

    @Override
    public void addEdge(Edge e) {
        throw new RuntimeException("Not support in this calss ,expected DirectedEdge");
    }
    public void addEdge(DirectedEdge e){
        adj[e.from()].put(e);
        E ++;
    }
}
